#include <iostream>
#include <math.h>
using namespace std;
int d[100005],v[100005],a[100005];
int r[100005];
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,l,V;
		cin>>n>>m>>l>>V;
		for(int i=1;i<=n;i++) scanf("%d%d%d",&d[i],&v[i],&a[i]);
		for(int i=1;i<=m;i++) scanf("%d",&r[i]);
		int cnt=0;
		for(int i=1;i<=n;i++)
		{
			int tem=sqrt(v[i]*v[i]+2*a[i]*(r[m]-d[i]));
			if(tem*tem!=v[i]*v[i]+2*a[i]*(r[m]-d[i])) tem++;
			if(d[i]<=r[m]&&tem>V) cnt++;
		}
		if(cnt==0) cout<<"0 "<<m<<endl;
		else cout<<cnt<<" "<<m-1<<endl;
	}
	return 0;
}
